package com.example.homework;

import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    TextView txt;
    Button bn1,bn2,bn4,bn5,bn7,bn8;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        txt = (TextView) findViewById(R.id.txt);

        bn1 = (Button)findViewById(R.id.bn1);
        bn1.setOnClickListener(this);

        bn2 = (Button)findViewById(R.id.bn2);
        bn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                txt.setText("点击了采用匿名内部类监听器");
            }
        });

        bn4 = (Button)findViewById(R.id.bn4);
        bn4.setOnClickListener(new MyClickListener());

        bn5 = (Button)findViewById(R.id.bn5);
        bn5.setOnClickListener(new MyButton(txt));



        bn7 = (Button)findViewById(R.id.bn7);
        bn7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this, ConfigurationTest.class);//this前面为当前activty名称，class前面为要跳转到得activity名称
                startActivity(intent);
            }
        });

        bn8 = (Button)findViewById(R.id.bn8);
        bn8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this, ProgressDialogTest.class);//this前面为当前activty名称，class前面为要跳转到得activity名称
                startActivity(intent);
            }
        });
    }

    @Override
    public void onClick(View source) {
        txt.setText("点击了采用Activity对象作为事件监听器");
    }

    public void clickHandler(View source) {
        txt.setText("点击了采用绑定到标签监听器");
    }

    class MyClickListener implements View.OnClickListener {
        @Override
        public void onClick(View v){
            txt.setText("点击了采用内部类监听器");
        }
    }
    public class MyButton implements View.OnClickListener{
        private TextView txt;
        private MyButton (TextView txt){
            super();
            this.txt = txt;
        }
        @Override
        public void onClick(View v){
            txt.setText("点击了采用外部类监听器");
        }
    }

}